package cn.cqie.frame.controller;


import cn.cqie.frame.bo.add.AddDeptBo;
import cn.cqie.frame.service.DeptService;
import cn.cqie.frame.vo.DeptVo;
import cn.cqie.frame.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author XYHL
 * @since 2021-10-09
 */
@RestController
@Api("部门管理")
public class DeptController {
    @Autowired
    private DeptService deptService;
    @ApiOperation("新增部门信息")
    @PostMapping(value = "/dept/saveOrUpdateDept")
    public ResultVo<DeptVo> saveOrUpdateDept(@Valid @RequestBody AddDeptBo bo) {
        DeptVo deptVo = deptService.saveOrUpdateDept(bo);
        return ResultVo.success(deptVo);
    }
    @ApiOperation("查询部门信息")
    @GetMapping(value = "/dept/queryDept")
    public ResultVo<List<DeptVo>> queryDept() {
        List<DeptVo> menuVoList = deptService.queryDept();
        return ResultVo.success(menuVoList);
    }
    @ApiOperation("上级部门备选项")
    @GetMapping(value = "/dept/listParentList")
    public ResultVo<List<DeptVo>> listParentList(Long id) {
        System.out.println(id);
        List<DeptVo> menuVoList = deptService.listParentList(id);
        return ResultVo.success(menuVoList);
    }
    @ApiOperation("删除部门信息")
    @DeleteMapping("/dept/deleteDept/{deptId}")
    public ResultVo<Void> deleteDept(@PathVariable Integer deptId) {
        Boolean delete = deptService.deleteDept(deptId);
        return delete ? ResultVo.success() : ResultVo.error("删除失败");
    }
}

